package com.fbinggun.fbinggunutil.plugin;

import io.lumine.mythic.api.adapters.AbstractLocation;
import io.lumine.mythic.api.mobs.MythicMob;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.bukkit.adapters.BukkitWorld;
import io.lumine.mythic.core.mobs.ActiveMob;
import org.bukkit.Location;
import org.bukkit.entity.Entity;

import java.util.Optional;

/**
 * MM插件API
 */
public class MMUtil {



    public static Entity spawnEntity(String id, Location loc){
       return spawnEntity(id,loc,0);
    }
    public static Entity spawnEntity(String id, Location loc,int level){
        Optional<MythicMob> mob= MythicBukkit.inst().getMobManager().getMythicMob(id);
        if(mob==null){
            return null;
        }else {
            if(mob.get()==null){
                return null;
            }
            MythicMob mythicMob=  mob.isPresent()?mob.get():null;
            if(mythicMob==null){
                return null;
            }
            AbstractLocation location = new AbstractLocation(new BukkitWorld(loc.getWorld()),loc.getX(),loc.getY(), loc.getZ());
            ActiveMob activeMob=  mythicMob.spawn(location,level);
            return activeMob.getEntity().getBukkitEntity();
        }
    }


}
